/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.merb.client.ui.maestros;

import co.com.merb.client.bosquejo.Bosquejos;
import co.com.merb.client.service.LoginService;
import co.com.merb.client.service.LoginServiceAsync;
import co.com.merb.shared.i18n.MerbConstants;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ScrollEvent;
import com.google.gwt.event.dom.client.ScrollHandler;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ScrolledEvent;
import com.smartgwt.client.widgets.events.ScrolledHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;

/**
 *
 * @author JAGO
 */
public class Cliente extends Window {

    private final MerbConstants constants;
    private final LoginServiceAsync serviceLogin;
    private final SectionStack sectionStack;
    private final SectionStack sectionStackBotones;
    private final SectionStackSection formation;
    private final SectionStackSection formationBotones;
    private final Bosquejos bosquejos;
    private final TextItem txtNombre;
    private final TextItem txtIdentificacion;
    private final TextItem txtPrimerApellido;
    private final TextItem txtSegundoApellido;
    private final TextItem txtTelefono;
    private final TextItem txtEmpresa;
    private final TextItem txtDirecc;
    private final TextItem txtEmail;
//    private final TextBox txtEjemplo;
    private final ButtonItem btnInsertar;
    private final ButtonItem btnBuscar;
    private final ButtonItem btnModificar;
    private final ButtonItem btnEliminar;
    private final ButtonItem btnLimpiar;
    private final DynamicForm loginForm;
    private final DynamicForm BotonesForm;

    public Cliente() {
        this.constants = GWT.create(MerbConstants.class);
        this.serviceLogin = GWT.create(LoginService.class);
        this.sectionStack = new SectionStack();
        this.sectionStackBotones = new SectionStack();
        this.formation = new SectionStackSection();
        this.formationBotones = new SectionStackSection();
        this.txtNombre = new TextItem();
        this.txtIdentificacion = new TextItem();
        this.txtPrimerApellido = new TextItem();
        this.txtSegundoApellido = new TextItem();
        this.txtTelefono = new TextItem();
        this.txtEmpresa = new TextItem();
        this.txtDirecc = new TextItem();
        this.txtEmail = new TextItem();

        this.btnInsertar = new ButtonItem(constants.Insertar());
        this.btnBuscar = new ButtonItem(constants.Buscar());
        this.btnModificar = new ButtonItem(constants.Modificar());
        this.btnEliminar = new ButtonItem(constants.Eliminar());
        this.btnLimpiar = new ButtonItem(constants.Limpiar());

        this.loginForm = new DynamicForm();
        this.BotonesForm = new DynamicForm();
        this.bosquejos = new Bosquejos();

        this.setComponents();
    }

    private void setComponents() {
//        setHeight100();
//        setWidth100();
        setHeight(500);
        setWidth(800);
        HLayout layout = new HLayout(20);  
        ScrolledHandler scrollHandler = new ScrolledHandler() {

            @Override
            public void onScrolled(ScrolledEvent event) {
               
            }
        };

        formation.setCanCollapse(false);
        formation.setExpanded(true);
        formationBotones.setCanCollapse(false);
        formationBotones.setExpanded(true);

        txtIdentificacion.setRequired(true);
        txtIdentificacion.setTooltip("Identificación del cliente");
        txtIdentificacion.setWidth(bosquejos.Anchotexto());
        txtIdentificacion.setHeight(bosquejos.Altotexto());
        txtIdentificacion.setRequiredMessage(constants.MensajeRequerido());
        txtIdentificacion.setTitle(constants.Identificacion());

        txtNombre.setRequired(true);
        txtNombre.setTooltip("Nombre del cliente");
        txtNombre.setWidth(bosquejos.Anchotexto());
        txtNombre.setHeight(bosquejos.Altotexto());
        txtNombre.setRequiredMessage(constants.MensajeRequerido());
        txtNombre.setTitle(constants.Nombres());
        
        txtPrimerApellido.setRequired(true);
        txtPrimerApellido.setTooltip("Primer apellido del cliente");
        txtPrimerApellido.setWidth(bosquejos.Anchotexto());
        txtPrimerApellido.setHeight(bosquejos.Altotexto());
        txtPrimerApellido.setRequiredMessage(constants.MensajeRequerido());
        txtPrimerApellido.setTitle(constants.PrimerApellido());

        txtSegundoApellido.setRequired(true);
        txtSegundoApellido.setWidth(bosquejos.Anchotexto());
        txtSegundoApellido.setHeight(bosquejos.Altotexto());
        txtSegundoApellido.setRequiredMessage(constants.MensajeRequerido());
        txtSegundoApellido.setTitle(constants.SegundApellido());

        txtTelefono.setRequired(true);
        txtTelefono.setWidth(bosquejos.Anchotexto());
        txtTelefono.setHeight(bosquejos.Altotexto());
        txtTelefono.setRequiredMessage(constants.MensajeRequerido());
        txtTelefono.setTitle(constants.telefono());

        txtEmpresa.setRequired(true);
        txtEmpresa.setWidth(bosquejos.Anchotexto());
        txtEmpresa.setHeight(bosquejos.Altotexto());
        txtEmpresa.setRequiredMessage(constants.MensajeRequerido());
        txtEmpresa.setTitle(constants.Empresa());

        txtDirecc.setRequired(true);
        txtDirecc.setWidth(bosquejos.Anchotexto());
        txtDirecc.setHeight(bosquejos.Altotexto());
        txtDirecc.setRequiredMessage(constants.MensajeRequerido());
        txtDirecc.setTitle(constants.Direccion());

        txtEmail.setRequired(true);
        txtEmail.setWidth(bosquejos.Anchotexto());
        txtEmail.setHeight(bosquejos.Altotexto());
        txtEmail.setRequiredMessage(constants.MensajeRequerido());
        txtEmail.setTitle(constants.Email());

//        txtNombre.setAlign(Alignment.CENTER);
//        txtIdentificacion.setAlign(Alignment.CENTER);
//        txtPrimerApellido.setAlign(Alignment.CENTER);
//        txtSegundoApellido.setAlign(Alignment.CENTER);
//        txtTelefono.setAlign(Alignment.CENTER);
//        txtEmpresa.setAlign(Alignment.CENTER);
//        txtDirecc.setAlign(Alignment.CENTER);
//        txtEmail.setAlign(Alignment.CENTER);
//        

//        btnInsertar.setColSpan(2);
        btnInsertar.setIcon(bosquejos.ImagenInsertar());
//        btnInsertar.setAlign(Alignment.CENTER);
        btnInsertar.setWidth(bosquejos.AnchoBoton());
        btnInsertar.setHeight(bosquejos.AltoBoton());
        btnInsertar.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Insertar();
            }
        });

        btnBuscar.setIcon(bosquejos.ImagenBuscar());
        btnBuscar.setAlign(Alignment.CENTER);
        btnBuscar.setWidth(bosquejos.AnchoBoton());
        btnBuscar.setHeight(bosquejos.AltoBoton());
        btnBuscar.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Buscar();
            }
        });

        btnModificar.setIcon(bosquejos.ImagenModificar());
        btnModificar.setAlign(Alignment.CENTER);
        btnModificar.setWidth(bosquejos.AnchoBoton());
        btnModificar.setHeight(bosquejos.AltoBoton());
        btnModificar.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Modificar();
            }
        });

        btnEliminar.setIcon(bosquejos.ImagenEliminar());
        btnEliminar.setAlign(Alignment.CENTER);
        btnEliminar.setWidth(bosquejos.AnchoBoton());
        btnEliminar.setHeight(bosquejos.AltoBoton());
        btnEliminar.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Eliminar();
            }
        });

        btnLimpiar.setIcon(bosquejos.ImagenEliminar());
        btnLimpiar.setAlign(Alignment.CENTER);
        btnLimpiar.setWidth(bosquejos.AnchoBoton());
        btnLimpiar.setHeight(bosquejos.AltoBoton());
        btnLimpiar.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Limpiar();
            }
        });
        btnInsertar.setColSpan(2);
        loginForm.setNumCols(4);
        loginForm.setPadding(10); 
//        loginForm.setLayoutAlign(VerticalAlignment.CENTER); setFields
//        FormItem[] {usernameItem, emailItem, passwordItem, password2Item}
        loginForm.setItems(txtIdentificacion, txtNombre,
                txtPrimerApellido, txtSegundoApellido, txtTelefono,
                txtEmpresa, txtEmail, txtDirecc);
        loginForm.setLeft(-125); 
        


        BotonesForm.setNumCols(10);
//        BotonesForm.setAlign(Alignment.CENTER);
        BotonesForm.setPadding(10); 
        BotonesForm.setItems(btnInsertar, btnBuscar, btnModificar, 
                btnEliminar, btnLimpiar);
        BotonesForm.setAlign(Alignment.CENTER);

        formation.setItems(loginForm);
        formationBotones.addItem(BotonesForm);
        sectionStack.setSections(formation);
        sectionStackBotones.setSections(formationBotones);
        setShowCloseButton(false);
        setShowMinimizeButton(false);
        setIsModal(true);
        setShowModalMask(true);
        setCanDragReposition(false);
        centerInPage();
        setShowTitle(false);
        addScrolledHandler(scrollHandler);
        setTitle(constants.TituloProyecto());
        addItem(sectionStack);
        addItem(sectionStackBotones);
    }

    private void Insertar() {
    }

    private void Buscar() {
    }

    private void Modificar() {
    }

    private void Eliminar() {
    }

    private void Limpiar() {
        LimpiarCampos();
    }

    public void LimpiarCampos() {
        txtNombre.clearValue();
        txtIdentificacion.clearValue();
        txtPrimerApellido.clearValue();
        txtSegundoApellido.clearValue();
        txtTelefono.clearValue();
        txtEmpresa.clearValue();
        txtDirecc.clearValue();
        txtEmail.clearValue();
    }
}
